package br.com.krk;

import java.util.ArrayList;
import java.util.HashMap;

import br.com.carcara.krk.R;
import br.com.carcara.krk.R.layout;
import br.com.carcara.krk.R.menu;
import br.com.control.Banco;
import android.os.Bundle;
import android.app.Activity;
import android.app.ListActivity;
import android.database.Cursor;
import android.view.Menu;
import android.widget.EditText;

public class ListaClienteActivity extends ListActivity {

	Banco _bd = new Banco(this);

	ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();

	private EditText edtFiltro;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.lista_cliente);
	}

	@Override
	protected void onResume() {
		ListarClientes(false);
		super.onResume();
	}

	public void ListarClientes(boolean usaFiltro) {
		HashMap<String, String> item;
		_bd.open();
		try {
			list.clear();
			Cursor _cursor = null;
			if (!usaFiltro) {
				_cursor = _bd.consulta("Cli", new String[] { "*" }, null, null,
						null, null, null, null);
			} else {
				_cursor = _bd.consulta("Cli", new String[] { "*" }, null, null,
						null, null, null, null);
			}
			item = new HashMap<String, String>();
			_cursor.moveToFirst();
			if (_cursor.getCount() > 0) {
				do {
					item = new HashMap<String, String>();
					item.put(
							"line1",
							_cursor.getString(_cursor.getColumnIndex("_CD_RET"))
									.toString()
									+ "-"
									+ _cursor.getString(
											_cursor.getColumnIndex("NOME"))
											.toString()
									+ "CPF_CNJP : "
									+ _cursor.getString(
											_cursor.getColumnIndex("CPF_CNJP"))
											.toString()
									+ "IE_RG : "
									+ _cursor.getString(
											_cursor.getColumnIndex("IE_RG"))
											.toString()
									+ "ENDERECO : "
									+ _cursor.getString(
											_cursor.getColumnIndex("ENDERECO"))
											.toString()
									+ "NUMERO : "
									+ _cursor.getString(
											_cursor.getColumnIndex("NUMERO"))
											.toString());
					item.put(
							"line2",
							"COMPLEMENTO : "
									+ _cursor
											.getString(
													_cursor.getColumnIndex("COMPLEMENTO"))
											.toString()
									+ " BAIRRO : "
									+ _cursor.getString(
											_cursor.getColumnIndex("BAIRRO"))
											.toString()
									+ "CEP : "
									+ _cursor.getString(
											_cursor.getColumnIndex("CEP"))
											.toString()
									+ "CIDADE : "
									+ _cursor.getString(
											_cursor.getColumnIndex("CIDADE"))
											.toString()
									+ "UF : "
									+ _cursor.getString(
											_cursor.getColumnIndex("UF"))
											.toString());
					list.add(item);
				} while (_cursor.moveToNext());
			}

			_cursor.close();
			_bd.fechaBanco();
		} catch (Exception e) {

		}

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.lista_cliente, menu);
		return true;
	}

}
